<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>Format Class - Fuel Documentation</title>
	<link href="../assets/css/main.css" media="screen" rel="stylesheet" />
	<script type="text/javascript" src="../assets/js/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="../assets/js/nav.js"></script>
	<script type="text/javascript" src="../assets/js/highlight.pack.js"></script>
	<script type="text/javascript">
		$(function() {
			show_nav('classes', '../');
		});
		hljs.tabReplace = '    ';
		hljs.initHighlightingOnLoad();
	</script>
</head>
<body>

	<header>
		<h1>Fuel Documentation</h1>
	</header>

	<div id="main-nav"></div>

	<section id="content">
		<h2>Format Class</h2>

		<p>The Format class helps you convert between various formats such as XML, JSON, CSV, etc.</p>
		
		<article>
			<h4 id="method_factory">factory($data = null, $from_type = null)</h4>
			<p>The <strong>factory</strong> method returns a new format object.</p>
			<table class="method">
				<tbody>
				<tr>
					<th class="legend">Static</th>
					<td>Yes</td>
				</tr>
				<tr>
					<th>Parameters</th>
					<td>
						<table class="parameters">
							<tr>
								<th>Param</th>
								<th>Default</th>
								<th class="description">Description</th>
							</tr>
							<tr>
								<th><kbd>$data</kbd></th>
								<td><pre class="php"><code>null</code></pre></td>
								<td>Data to be converted.</td>
							</tr>
							<tr>
								<th><kbd>$from_type</kbd></th>
								<td><pre class="php"><code>null</code></pre></td>
								<td>Format of the data provided.</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<th>Returns</th>
					<td>Fuel\Core\Format Object</td>
				</tr>
				<tr>
					<th>Example</th>
					<td>
						<pre class="php"><code>$array = array('foo' => 'bar');
print_r( Format::factory( $array ) );

// Returns
Fuel\Core\Format Object
(
	[_data:protected] => Array
		(
			[foo] => bar
		)
)</code>
						</pre>
					</td>
				</tr>
				</tbody>
			</table>
		</article>
		
		<article>
			<h4 id="method_to_array">to_array($data = null)</h4>
			<p>The <strong>to_array</strong> method returns the given data as an array. Do not call this directly, use the <strong>factory</strong> method as described in the example.</p>
			<table class="method">
				<tbody>
				<tr>
					<th class="legend">Static</th>
					<td>No</td>
				</tr>
				<tr>
					<th>Parameters</th>
					<td>
						<table class="parameters">
							<tr>
								<th>Param</th>
								<th>Default</th>
								<th class="description">Description</th>
							</tr>
							<tr>
								<th><kbd>$data</kbd></th>
								<td><pre class="php"><code>null</code></pre></td>
								<td>Data to be converted.</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<th>Returns</th>
					<td>array</td>
				</tr>
				<tr>
					<th>Example</th>
					<td>
						<pre class="php"><code>$json_string = '{"foo":"bar","baz":"qux"}';
print_r( Format::factory( $json_string, 'json' )->to_array() );

// Returns
Array
(
    [foo] => bar
    [baz] => qux
)</code>
						</pre>
					</td>
				</tr>
				</tbody>
			</table>
		</article>
		
		<article>
			<h4 id="method_to_xml">to_xml($data = null, $structure = null, $basenode = 'xml')</h4>
			<p>The <strong>to_xml</strong> method returns the given data as an XML string. Do not call this directly, use the <strong>factory</strong> method as described in the example.</p>
			<table class="method">
				<tbody>
				<tr>
					<th class="legend">Static</th>
					<td>No</td>
				</tr>
				<tr>
					<th>Parameters</th>
					<td>
						<table class="parameters">
							<tr>
								<th>Param</th>
								<th>Default</th>
								<th class="description">Description</th>
							</tr>
							<tr>
								<th><kbd>$data</kbd></th>
								<td><pre class="php"><code>null</code></pre></td>
								<td>Data to be converted.</td>
							</tr>
							<tr>
								<th><kbd>$structure</kbd></th>
								<td><pre class="php"><code>null</code></pre></td>
								<td>Object of class SimpleXMLElement.</td>
							</tr>
							<tr>
								<th><kbd>$basenode</kbd></th>
								<td>"xml"</td>
								<td>Basenode of XML markup.</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<th>Returns</th>
					<td>string</td>
				</tr>
				<tr>
					<th>Example</th>
					<td>
						<pre class="php"><code>$array = array('foo' => 'bar', 'baz' => 'qux');
print_r( Format::factory( $array )->to_xml() );

// Returns
// &lt;?xml version="1.0" encoding="utf-8"?&gt;
// &lt;xml&gt;
// 	&lt;foo&gt;bar&lt;/foo&gt;
// 	&lt;baz&gt;qux&lt;/baz&gt;
// &lt;/xml&gt;</code>
						</pre>
					</td>
				</tr>
				</tbody>
			</table>
		</article>
		
		<article>
			<h4 id="method_to_csv">to_csv()</h4>
			<p>The <strong>to_csv</strong> method returns the given data as a CSV string. Do not call this directly, use the <strong>factory</strong> method as described in the example.</p>
			<table class="method">
				<tbody>
				<tr>
					<th class="legend">Static</th>
					<td>No</td>
				</tr>
				<tr>
					<th>Returns</th>
					<td>string</td>
				</tr>
				<tr>
					<th>Example</th>
					<td>
						<pre class="php"><code>$json_string = '{"foo":"bar","baz":"qux"}';
print_r( Format::factory( $json_string, 'json' )->to_csv() );

// Returns
//
// foo,baz
// "bar","qux"</code>
						</pre>
					</td>
				</tr>
				</tbody>
			</table>
		</article>
		<article>
			<h4>to_json()</h4>
			<p>The <strong>to_json</strong> method returns the given data as a JSON string. Do not call this directly, use the <strong>factory</strong> method as described in the example.</p>
			<table class="method">
				<tbody>
				<tr>
					<th class="legend">Static</th>
					<td>No</td>
				</tr>
				<tr>
					<th>Returns</th>
					<td>string</td>
				</tr>
				<tr>
					<th>Example</th>
					<td>
						<pre class="php"><code>$array = array('foo' => 'bar', 'baz' => 'qux');
print_r( Format::factory( $array )->to_json() );

// Returns
// {"foo":"bar","baz":"qux"}</code>
						</pre>
					</td>
				</tr>
				</tbody>
			</table>
		</article>
		
		<article>
			<h4 id="method_to_serialized">to_serialized()</h4>
			<p>The <strong>to_serialized</strong> method returns the given data as a serialized string. Do not call this directly, use the <strong>factory</strong> method as described in the example.</p>
			<table class="method">
				<tbody>
				<tr>
					<th class="legend">Static</th>
					<td>No</td>
				</tr>
				<tr>
					<th>Returns</th>
					<td>string</td>
				</tr>
				<tr>
					<th>Example</th>
					<td>
						<pre class="php"><code>$array = array('foo' => 'bar', 'baz' => 'qux');
print_r( Format::factory( $array )->to_serialized() );

// Returns
// a:2:{s:3:"foo";s:3:"bar";s:3:"baz";s:3:"qux";}</code>
						</pre>
					</td>
				</tr>
				</tbody>
			</table>
		</article>
		
		<article>
			<h4 id="method_to_php">to_php()</h4>
			<p>The <strong>to_php</strong> method returns the given data as a PHP representation of the data in a string. You could pass this into eval() or use it for other crazy things.</p>
			<table class="method">
				<tbody>
				<tr>
					<th class="legend">Static</th>
					<td>No</td>
				</tr>
				<tr>
					<th>Returns</th>
					<td>string</td>
				</tr>
				<tr>
					<th>Example</th>
					<td>
						<pre class="php"><code>$array = array (1, 2, array ("a", "b", "c"));
echo Format::factory( $array )->to_php();

// Returns
"array (
  0 => 1,
  1 => 2,
  2 => 
  array (
    0 => 'a',
    1 => 'b',
    2 => 'c',
  ),
)"</code>
						</pre>
					</td>
				</tr>
				</tbody>
			</table>
		</article>
	</section>

	<section id="footer">
		<p>
			<a href="http://fuelphp.com">Fuel</a> is released under the MIT license.<br />
			&copy; 2010 - 2011 Fuel Development Team
		</p>
	</section>

</body>
</html>